package com.example.user.utils;
import java.util.Date;

import cn.hutool.core.util.RandomUtil;
import com.example.user.entity.User;
import org.apache.commons.lang.math.RandomUtils;


import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author: mtl
 * @Date: 2022/1/20 15:16
 * @Description:
 */
public class demo {

    public static void main(String[] args) {
        List<User> userList = getUserList(100000);
        System.out.println(userList);
    }


    /**
     * 生成用户数据
     * @param size
     * @return
     */
    public static List<User> getUserList(Integer size){
        List<User> list = new ArrayList<>();
        for(int i = 0; i < size; i++){
            User user = new User();
            user.setState(false);
            user.setName(getRandomChar(4));
            user.setHeadImgUrl(RandomUtil.randomString(20));
            user.setMobile(RandomUtil.randomNumbers(11));
            user.setSalt(RandomUtil.randomNumbers(6));
            user.setPassword(RandomUtil.randomNumbers(6));
            user.setCreated(new Date());
            user.setCreator("admin");
            user.setEdited(new Date());
            user.setEditor("admin");
            user.setDeleted(false);
            list.add(user);
        }
        return list;
    }

    private static String getRandomChar(Integer size) {
        StringBuilder strs = new StringBuilder();
        for(int i = 0; i < size; i++){
            String str = "";
            int hightPos; //
            int lowPos;
            Random random = new Random();
            hightPos = (176 + Math.abs(random.nextInt(39)));
            lowPos = (161 + Math.abs(random.nextInt(93)));
            byte[] b = new byte[2];
            b[0] = (Integer.valueOf(hightPos)).byteValue();
            b[1] = (Integer.valueOf(lowPos)).byteValue();
            try {
                str = new String(b, "GBK");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                System.out.println("错误");
            }
            strs.append(str);
        }
        return strs.toString();
    }

}
